package com.sec.security.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.sec.base.utils.AjaxJson;
import com.sec.security.service.SecurityService;

@RestController
@RequestMapping(value = "/security")
@CrossOrigin
public class SecurityController {

	@Autowired
	private SecurityService securityService;

	/**
	 * 文字加密
	 * 
	 * @param originalText
	 * @param password
	 * @return
	 */
	@RequestMapping(value = "encryptTxt", method = RequestMethod.POST)
	public AjaxJson encryptTxt(HttpServletRequest request, String originalText, String password) {
		return securityService.encryptTxt(request, originalText, password);
	}

	/**
	 * 文字解密
	 * 
	 * @param cipherText
	 * @param password
	 * @return
	 */
	@RequestMapping(value = "decryptTxt", method = RequestMethod.POST)
	public AjaxJson decryptTxt(HttpServletRequest request, String cipherText, String password) {
		return securityService.decryptTxt(request, cipherText, password);
	}

	/**
	 * 图片加密
	 * 
	 * @param file
	 * @param request
	 * @param picPassword
	 * @return
	 */
	@RequestMapping(value = "encryptPic", method = RequestMethod.POST)
	public AjaxJson encryptPic(MultipartFile file, HttpServletRequest request, String password) {
		return securityService.encryptPic(file, request, password);
	}

	/**
	 * 图片解密
	 * 
	 * @param request
	 * @param response
	 * @param content
	 * @param password
	 */
	@RequestMapping(value = "/decryptPic", method = RequestMethod.POST)
	public AjaxJson decryptPic(HttpServletRequest request, String content, String password) {
		return securityService.decryptPic(request, content, password);
	}
}
